import React from "react";
import BaseComponent from "@/BaseComponent";
import { connect } from "react-redux";
import { Link, Switch } from "react-router-dom";
import "./Home.less";

import { homeRoute } from "@routes/";
import AuthRoute from "@components/AuthRoute";
import { Button } from "antd";

class Home extends BaseComponent {
  constructor(props) {
    super(props);
    this.state = {};
  }

  render() {
    return (
      <div>
        Home页面
        <h1>
          用户姓名:
          {this.props.userInfo.get('username')}
        </h1>
        <nav>
          {homeRoute.children.map((route) => (
            <Button key={route.path} type="primary">
              <Link to={route.path}>{route.title}</Link>
            </Button>
          ))}
        </nav>
        <Switch>
          {homeRoute.children.map((route) => (
            <AuthRoute key={route.path} {...route} />
          ))}
        </Switch>
      </div>
    );
  }
}

const mapStateToProps = (state) => ({
  userInfo: state.userReducer.get("userInfo"),
});

export default connect(mapStateToProps)(Home);
